import request from '../utils/request';
import {localData} from 'kuan-utils'

const cache = {
  key: 'yun_h5_upload_token',
  get() {
    return localData.get(this.key)
  },
  set(token) {
    localData.set(this.key, token, 60 * 60 * 12)
  }
}

// 获取上传token
export async function uploadToken() {
  const cacheToken = cache.get()
  if (cacheToken) {
    return cacheToken
  }
  const {data: {token}} = await request({
    url: '/api/dashboard/v1/upload/token'
  })
  if (token) cache.set(token)
  return token
}
